include( 'init.lua' )
include( 'shared.lua' )

-- Thanks to Kogitsune for this! The roll ability
function _R.Player:SpinTo( deg, time )
	self.__spin_deg = deg
	self.__spin_time = time
	self.__spin = true
	self.__pitch = self:GetAngles( ).p
end

local function umSpinTo( um )
	local a, b

	a = um:ReadFloat( )
	b = um:ReadFloat( )

	LocalPlayer():SpinTo( a, b )
end

usermessage.Hook( "Spin To", umSpinTo )

local function CalcView( pl, pos, ang, fov )
	local view
	
	if not pl.__spin then
		return
	end
	
	view = GAMEMODE:CalcView( pl, pos, ang, fov )
	
	pl.__pitch = math.Approach( pl.__pitch, pl.__spin_deg, FrameTime( ) * pl.__spin_time * pl.__spin_deg )
	
	if pl.__pitch == pl.__spin_deg then
		pl.__spin = false
	end
	
	view.angles.p = pl.__pitch
	
	return view
end

hook.Add( "CalcView", "Spin View.CalcView", CalcView )


// Clientside only stuff goes here

--custom spawn menu
function proplist()
		print ("List Opening")
		local props = {}
 
props[1] = "rnw_spawnrifleman"
props[2] = "rnw_spawnshotgunmedic"
props[3] = "rnw_spawnbarricade"
	 
	local slframe = vgui.Create("DFrame")
	local IconList = vgui.Create("DPanelList", slframe)

      slframe:SetPos( ScrW() /20, ScrH()/7. )
	slframe:SetSize(250,200)
	slframe:SetTitle(" Units ")
	slframe:MakePopup()
 
	IconList:EnableVerticalScrollbar( true )
	IconList:EnableHorizontal( true )
	IconList:SetPadding( 4 )
	IconList:SetPos(10,30)
	IconList:SetSize(200,160)
 
	for k,v in pairs(props) do
	local icon = vgui.Create( "SpawnIcon", IconList )
	icon:SetModel( v )
	IconList:AddItem( icon )
	icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand( v ) end
	end

local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 20, ScrH() / 2.5 ) 
frame:SetSize( 250, 200 ) --Set the size
frame:SetTitle( "Change Team" ) --Set title
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( slframe:GetTall() / 2, 5 ) --Place it half way on the tall and 5 units in horizontal
team_1:SetSize( 50, 100 )
team_1:SetText( "Rebel" )
team_1.DoClick = function() --Make the player join team 1
    RunConsoleCommand( "team_1" )
    gui.EnableScreenClicker( false ) 
end

team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( slframe:GetTall() / 2, 105 ) --Place it next to our previous one
team_2:SetSize( 50, 100 )
team_2:SetText( "Combine" )
team_2.DoClick = function() --Make the player join team 2
    RunConsoleCommand( "team_2" )
    gui.EnableScreenClicker( false ) 
    
end


end
concommand.Add("slist", proplist)
 
function GM:OnSpawnMenuOpen( ply )
LocalPlayer():ConCommand("slist")
end
